import type { IFieldProps, IConfigProps } from '@/components/sofastui/AdvancedTable/interface'
import type { FormRule } from '@form-create/element-ui'

export const fields: IFieldProps[] = [
  {
    label: '组织ID',
    prop: 'id',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
    select: false,
  },
  {
    label: '组织名称',
    prop: 'name',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '组织简称',
    prop: 'abbreviation',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '组织编码',
    prop: 'code',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '组织类型',
    prop: 'orgType.name',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '组织描述',
    prop: 'desc',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '创建时间',
    prop: 'createdAt',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
    select: false,
  },
  {
    label: '修改时间',
    prop: 'updatedAt',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
    select: false,
  },
]

export const config: IConfigProps = {
  name: 'powOrgTable',
  rowKey: 'id',
  url: '/api/idt/org',
  selection: true,
  add: true,
  delete: true,
  expand: true,
  showIndex: true,
  import: true,
  export: true,
  search: true,
  advancedSearch: true,
  refresh: true,
  settings: true,
}

export const formRules: FormRule = [
  {
    type: 'select',
    field: 'orgTypeId',
    title: '组织类型',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data.map(i=>({label:i.name,value:i.id}));\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'options',
        action: '/api/idt/org_type',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: true,
    props: {
      _optionType: 3,
      clearable: true,
    },
    _fc_id: 'id_Fwh5mc35zbnbchc',
    name: 'orgTypeId',
    display: true,
    hidden: false,
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
  },
  {
    type: 'elTreeSelect',
    field: 'parentId',
    title: '上级组织',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data;\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'props.data',
        action: '/api/idt/org/tree',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: false,
    props: {
      nodeKey: 'id',
      showCheckbox: false,
      _optionType: 3,
      expandOnClickNode: false,
      props: {
        label: 'name',
      },
      checkStrictly: true,
      clearable: true,
    },
    _fc_id: 'id_Frq7mc97xi4nahc',
    name: 'parentId',
    display: true,
    hidden: false,
    _fc_drag_tag: 'elTreeSelect',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'name',
    title: '组织名称',
    $required: true,
    props: {
      placeholder: '请输入组织名称',
    },
    _fc_id: 'id_F2abmc34zpa2bnc',
    name: 'name',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'abbreviation',
    title: '组织简称',
    $required: false,
    props: {
      placeholder: '请输入组织简称',
    },
    _fc_id: 'id_Fscqmc3516c5btc',
    name: 'abbreviation',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'code',
    title: '组织编码',
    $required: true,
    props: {
      placeholder: '请输入组织编码',
    },
    _fc_id: 'id_Fja7mc22xer3alc',
    name: 'code',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'inputNumber',
    field: 'orderNum',
    title: '排序值',
    $required: false,
    props: {
      controls: true,
      controlsPosition: 'right',
      step: 1,
      min: 0,
    },
    _fc_id: 'id_Fdcqmc36vnpockc',
    name: 'orderNum',
    value: 0,
    display: true,
    hidden: false,
    _fc_drag_tag: 'inputNumber',
    col: {
      span: 12,
    },
    style: {
      width: '100%',
    },
  },
  {
    type: 'input',
    field: 'desc',
    title: '组织描述',
    $required: false,
    props: {
      type: 'textarea',
      placeholder: '请输入组织描述',
    },
    _fc_id: 'id_Fwn9mc22xutzaoc',
    name: 'desc',
    display: true,
    hidden: false,
    _fc_drag_tag: 'textarea',
    col: {
      span: 24,
    },
  },
]
